package com.goodving.guli.bt.weight.family;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.goodving.guli.R;
import com.goodving.guli.bt.C0668a;
import com.goodving.guli.bt.DimPanelFragment;
import com.goodving.guli.bt.eventbus.EventPersonInfoUpdate;
import com.goodving.guli.bt.eventbus.EventUserInfoUpdate;
import com.goodving.guli.bt.model.PersonInfo;
import com.goodving.guli.bt.profile.scale.GuliLog;
import com.goodving.guli.bt.weight.UserInfo;
import com.goodving.guli.bt.weight.UserInfoManager;
import com.goodving.guli.model.Keeper;

import de.greenrobot.event.EventBus;

/**
 * Created by john on 2015/12/17.
 */
public class dd extends DimPanelFragment {
    private static final String f9927a;
    private static int f9928k;
    private PersonInfo f9929b;
    private UserInfo f9930c;
    private View f9931d;
    private View f9932e;
    private View f9933f;
    private View f9934g;
    private TextView f9935h;
    private TextView f9936i;
    private int f9937j;

    static {
        f9927a = dd.class.getSimpleName();
    }

    public dd() {
        this.f9937j = 0;
    }

    public static Fragment m14648a(int i) {
        GuliLog.tracePrintInfo(f9927a, "receive the uid" + i);
        f9928k = i;
        return new dd();
    }

    private void m14649a() {
        if (this.f9937j == 1) {
            this.f9931d.setVisibility(View.VISIBLE);
            this.f9932e.setVisibility(View.INVISIBLE);
            this.f9936i.setTextColor(getResources().getColor(R.color.highlight));
            this.f9935h.setTextColor(getResources().getColor(R.color.main_ui_title_color));
        } else if (this.f9937j == 0) {
            this.f9931d.setVisibility(View.INVISIBLE);
            this.f9932e.setVisibility(View.VISIBLE);
            this.f9935h.setTextColor(getResources().getColor(R.color.highlight));
            this.f9936i.setTextColor(getResources().getColor(R.color.main_ui_title_color));
        }
    }

    protected int inflateLayout() {
        return R.layout.fragment_person_info_setting_gender;
    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.person_info_male_area:
                this.f9937j = 1;
                onRightButtonClicked();
                break;
            case R.id.person_info_female_area:
                this.f9937j = 0;
                onRightButtonClicked();
                break;
        }
        super.onClick(view);
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        if (f9928k == -1) {
            this.f9929b = Keeper.readPersonInfo();
        } else {
            this.f9930c = UserInfoManager.getInstance().getInfoByUid(f9928k);
        }
    }

    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View onCreateView = super.onCreateView(layoutInflater, viewGroup, bundle);
        this.f9931d = onCreateView.findViewById(R.id.info_gender_male);
        this.f9932e = onCreateView.findViewById(R.id.info_gender_female);
        this.f9933f = onCreateView.findViewById(R.id.person_info_female_area);
        this.f9933f.setOnClickListener(this);
        this.f9934g = onCreateView.findViewById(R.id.person_info_male_area);
        this.f9934g.setOnClickListener(this);
        this.f9935h = (TextView) onCreateView.findViewById(R.id.info_gender_female_txt);
        this.f9936i = (TextView) onCreateView.findViewById(R.id.info_gender_male_txt);
        if (this.f9929b != null) {
            this.f9937j = this.f9929b.gender;
        } else {
            this.f9937j = this.f9930c.gender;
        }
        m14649a();
        return onCreateView;
    }

    public void onDestroy() {
        super.onDestroy();
    }

    public void onPause() {
        super.onPause();
        C0668a.m8141b(C0668a.f3564g);
    }

    public void onResume() {
        super.onResume();
        C0668a.m8133a(C0668a.f3564g);
    }

    protected void onRightButtonClicked() {
        m14649a();
        if (this.f9929b != null) {
            if (this.f9937j == this.f9929b.gender) {
                dismiss();
                return;
            }
            this.f9929b.gender = this.f9937j;
            this.f9929b.setNeedSyncServer(2);
            Keeper.keepPersonInfo(this.f9929b);
            EventBus.getDefault().post(new EventPersonInfoUpdate(null));
        } else if (this.f9937j == this.f9930c.gender) {
            dismiss();
            return;
        } else {
            this.f9930c.gender = this.f9937j;
            EventBus.getDefault().post(new EventUserInfoUpdate(this.f9930c));
        }
        dismiss();
    }
}
